package cn.tedu.tourism.passenger.service.impl;

import cn.tedu.tourism.passenger.mapper.PassengerMapper;
import cn.tedu.tourism.passenger.pojo.dto.PassengerParam;
import cn.tedu.tourism.passenger.pojo.entity.Passenger;
import cn.tedu.tourism.passenger.pojo.vo.PassengerVO;
import cn.tedu.tourism.passenger.service.PassengerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class PassengerServiceImpl implements PassengerService {
    @Autowired
    private PassengerMapper passengerMapper;

    @Override
    public List<PassengerVO> selectByUserId(Long userId) {
        log.debug("查询旅客信息业务：{}",userId);
        List<PassengerVO> list = passengerMapper.selectByUserId(userId);
        return list;
    }

    @Override
    public void save(PassengerParam passengerParam) {
        log.debug("保存旅客信息业务：{}",passengerParam);
        Passenger passenger = new Passenger();
        BeanUtils.copyProperties(passengerParam,passenger);
        if (passengerParam.getId() == null) {
            passenger.setCreatedTime(new Date());
            passengerMapper.insert(passenger);
        }else{
            passenger.setCreatedTime(new Date());
            passengerMapper.update(passenger);
        }
    }

    @Override
    public List<PassengerVO> selectById(Long id) {
        log.debug("查询旅客详细信息业务：{}",id);
        List<PassengerVO> list = passengerMapper.selectById(id);
        return list;
    }

    @Override
    public void delete(Long id) {
        log.debug("删除旅客信息业务：{}",id);
        passengerMapper.delete(id);
    }
}
